(*
 *
 *)


#use "parser.ml";;
#use "circularqueue.ml";;

module MyQueue = CQ;;

#use "strmap.ml";; 
#use "strenv.ml";;

module MyMap = PrefixTree;;
module MyEnv = Env(PrefixTree);;

#use "strheap.ml";;

module MyHeap = Heap(PrefixTree) ;;

#use "am.ml";;

#use "pp.ml";;


let rec mainLoop amObj count =
        let str = read_line()
        in match str with
         "quit" | "end" | "exit" -> ()
        | "" ->  go 1 amObj count
	| num -> (try
		   let n = int_of_string num in go n amObj count
                 with x ->
                      (print_string "...atteso <int> per numero di next..."; print_newline (); flush_all (); 
                      mainLoop amObj count))

and go n amObj count =
	flush_all (); print_newline ();flush_all();
	print_string ("================ "^(string_of_int count)^" =================");
	flush_all (); print_newline ();flush_all();
	(try
	   pnextn amObj n
        with x -> print_newline(); print_string "!!!"; raise x);
	mainLoop amObj (count + n) ;;


let execute str = 
	let ast =  ((new picparser(new picscanner str))#beginparse) in
        let amObj = new picmodel(ast) in 
		print_newline ();
		print_string (ast2pl ast);
		print_newline ();
		flush_all ();
		mainLoop amObj 0;;
